#include <UI/UIWindow.h>

namespace ne
{
    UIWindow::UIWindow(const std::string &name)
        : UIObject(name),
          mpFontGeometry(new DynamicGeometry(PT_TRIANGLES)),
          mpAtlasGeometry(new DynamicGeometry(PT_TRIANGLES))
    {
    }

    void UIWindow::setFont(const FontPtr &pFont)
    {
        mpFont = pFont;
    }

    FontPtr UIWindow::getFont() const
    {
        return mpFont;
    }

    void UIWindow::setAtlas(const AtlasPtr &pAtlas)
    {
        mpAtlas = pAtlas;
    }

    AtlasPtr UIWindow::getAtlas() const
    {
        return mpAtlas;
    }

    DynamicGeometryPtr UIWindow::getFontGeometry() const
    {
        return mpFontGeometry;
    }

    DynamicGeometryPtr UIWindow::getAtlasGeometry() const
    {
        return mpAtlasGeometry;
    }

    UIWindow::~UIWindow()
    {
    }

    bool UIWindow::_renderSelf()
    {
        if (isVisible())
        {
            _genAtlasGeometry(mpAtlasGeometry, mpAtlas);
            return true;
        }
        return false;
    }

    bool UIWindow::_renderAll()
    {
        mpFontGeometry->beginGeometry();
        mpAtlasGeometry->beginGeometry();
        if (_renderSelf())
        {
            for (NodeSetIterator it=mChildren.begin(); it!=mChildren.end(); ++it)
            {
                UIObject *child = dynamic_cast<UIObject*>(*it);
                child->_renderAll();
            }
        }
        mpAtlasGeometry->endGeometry();
        mpFontGeometry->endGeometry();
        return isVisible();
    }
}
